﻿#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;

#include<algorithm>
#include<vector>

void test1()
{
	vector<int> vc;
	vc.push_back(12);
	vc.push_back(2);
	vc.push_back(23);
	vc.push_back(432);
	vc.push_back(15);

	for (size_t i = 0; i < vc.size(); i++)
	{
		cout << vc[i] << " ";
	}
	cout << endl;


	vector<char> vc2(5, 'c');
	for (size_t i = 0; i < vc2.size(); i++)
	{
		cout << vc2[i] << " ";
	}

	cout << endl;

	sort(vc.begin(), vc.end(), greater<int>());
	for (size_t i = 0; i < vc.size(); i++)
	{
		cout << vc[i] << " ";
	}
	cout << endl;
}

void test2()
{
	vector<int> vc;
	vc.push_back(2);
	vc.push_back(12);
	vc.push_back(22);
	vc.push_back(32);
	vc.push_back(42);
	vc.push_back(52);
	vector<int>::iterator it1 = vc.begin();
	while (it1 != vc.end())
	{
		cout << *it1 << " ";
		it1++;
	}
	cout << endl;

	it1 = vc.begin();
	while (it1 != vc.end())
	{
		*it1 = *it1 + 100;
		cout << *it1 << " ";
		it1++;
	}
	cout << endl;

	vector<int>::reverse_iterator it2 = vc.rbegin();
	while (it2 != vc.rend())
	{
		cout << *it2 << " ";
		++it2;
	}
	cout << endl;
}

void test3()
{
	vector<int> vc;
	vc.resize(10, 0);
	vector<int>::iterator it = vc.begin();
	while (it != vc.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	vc.resize(20,11);
	it = vc.begin();
	while (it != vc.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;
}

void test4()
{
	vector<char> vc;
	vc.push_back('a');
	vc.push_back('b');
	vc.push_back('c');
	vc.push_back('d');
	vc.push_back('e');
	vc.push_back('f');

	for (char& e : vc)
	{
		//e += 1;
		cout << e << " ";
	}
	cout << endl;

	vc.pop_back();
	vc.pop_back();
	for (char& e : vc)
	{
		//e += 1;
		cout << e << " ";
	}
	cout << endl;
}

void test5()
{
	vector<int> v{ 1,2,3,4,5 };

	cout << v[6] << endl;

	vector<int>::iterator pos = find(v.begin(), v.end(),3);

	//find函数要是找不到，会返回end
	if (pos != v.end())
	{
		v.insert(pos, 29);
	}

	vector<int>::iterator it = v.begin();
	while (it != v.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	pos = find(v.begin(), v.end(), 3);
	v.erase(pos);

	it = v.begin();
	while (it != v.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;
}

void test6()
{
	vector<int>v(5, 1);
	cout << v.capacity() << endl;
	v.reserve(100);
	cout << v.capacity() << endl;
	v.reserve(20);
	cout << v.capacity() << endl;

}

int main()
{
	//test1();
	//test2();
	//test3();
	//test4();
	//test5();
	test6();
	return 0;
}

class Solution {
public:
	int singleNumber(vector<int>& nums) {
		int ret = 0;
		for (int i = 0; i < nums.size(); i++)
		{
			ret ^= nums[i];
		}
		return ret;
	}
};

vector<vector<int>> generate(int numRows) {
	vector<vector<int>> vv(numRows);
	for (int i = 0; i < numRows; i++)
	{
		vv[i].resize(i + 1, 0);
	}

	for (int i = 0; i < numRows; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (i == j || j == 0)
			{
				vv[i][j] = 1;
			}
			else
			{
				vv[i][j] = vv[i - 1][j] + vv[i - 1][j - 1];
			}
		}
	}
	return vv;
}

int removeDuplicates(vector<int>& nums) {
	int slow = 0;
	int fast = slow + 1;
	while (fast < nums.size())
	{
		if (nums[slow] != nums[fast])
		{
			slow++;
			nums[slow] = nums[fast];
		}
		fast++;
	}
	return slow + 1;//返回个数
}


int singleNumber(vector<int>& nums) {
	int ret = 0;
	for (int i = 0; i < 32; i++)
	{
		int count = 0;
		for (int j = 0; j < nums.size(); j++)
		{
			if ((nums[j] >> i) & 1)
			{
				count++;
			}
		}
		if (count % 3 != 0)
		{
			ret |= 1 << i;
		}
	}
	return ret;
}
